function Received (evt) {
	var received_msg = evt.data;
	//document.getElementById('test-id2').innerHTML = received_msg;
        //alert("Message is received...");
	if(received_msg == "F")
		OwnPlayer.fire();
	if(received_msg.substr(0,1) == "S")
		OtherPlayer.setKey(parseInt(received_msg.substr(1),10));
	if(received_msg.substr(0,1) == "X")
		OtherPlayer.setX(parseInt(received_msg.substr(1),10));
	if(received_msg.substr(0,1) == "Y")
		OtherPlayer.setY(parseInt(received_msg.substr(1),10));
	if(received_msg.substr(0,1) == "N") {
		curPlayer = (parseInt(received_msg.substr(1),10)) % 2;
		document.getElementById('test-id2').innerHTML = curPlayer;
		
	}
	if(received_msg.substr(0,1) == "R")
		//document.getElementById('test-id2').innerHTML = "release " + parseInt(received_msg.substr(1),10);
		OtherPlayer.unsetKey(parseInt(received_msg.substr(1),10));
}
	
function keyrelease ( event ) {
  if(typeof keys[event.keyCode] != 'undefined') {
    event.preventDefault();
    //document.getElementById(keys[event.keyCode][2]).style.backgroundColor = "white";
    keys[event.keyCode][1] = 0;
	OwnPlayer.unsetKey(event.keyCode);
    WebSocketSend("R"+event.keyCode);
  }
}

function keypressed ( event ) {
    //alert( event.keyCode );
    if(typeof keys[event.keyCode] != 'undefined') {
      event.preventDefault();
      if(keys[event.keyCode][1] == 0) {
		keys[event.keyCode][1] = 1;
		OwnPlayer.setKey(event.keyCode);
		
		//alert("11");
		if(keys[event.keyCode][2] == "fire") {
				OtherPlayer.fire();
				WebSocketSend("F");
		}
		WebSocketSend("S"+event.keyCode);
      }
	  
    }
}
setTimeout(function() {
	WebSocketSend("X" + Math.floor(OwnPlayer.getX()));
	WebSocketSend("Y" + Math.floor(OwnPlayer.getY()));
	setTimeout(arguments.callee, 250);
}, 250);